/*
* Conditions Of Use
*
* This software was developed by employees of the Sigmatrix(Beijing) Corporation.
* This software is provided by sigmatrix as a service and is expressly
* provided "AS IS."  Sigmatrix MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
* AND DATA ACCURACY.  Sigmatrix does not warrant or make any representations
* regarding the use of the software or the results thereof, including but
* not limited to the correctness, accuracy, reliability or usefulness of
* the software.
*
* Permission to use this software is contingent upon your acceptance
* of the terms of this agreement.
*
*/
package com.sigmatrix.h5.web.controller;


import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.sigmatrix.h5.enums.ResponseEnum;
import com.sigmatrix.h5.exception.ServiceException;
import com.sigmatrix.h5.response.Response;
import com.sigmatrix.h5.service.SyncTaskService;
import com.sigmatrix.h5.utils.Cons;
import com.sigmatrix.h5.web.controller.common.BaseController;
import com.sigmatrix.h5.web.vo.SyncTaskVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * @ClassName: SyncTaskController
 * @Description: 异步任务控制器
 * @author youjun 
 * @date 2017-11-27 16:04:46
 */
@Api(value="异步任务相关接口", tags="异步任务接口")
@RestController
@RequestMapping("/app/synctask")
public class SyncTaskController extends BaseController {

	/**logger record*/
	private static final Logger LOGGER = LoggerFactory.getLogger(SyncTaskController.class);

	/**异步任务业务层接口*/
	@Autowired
	private transient SyncTaskService syncTaskService;

	/**
	 * 
	 *@Title: getById
	 *@Description: TODO()
	 *@return Response
	 *@author youjun
	 *@date 2017年11月27日 下午8:30:29
	 *@param request
	 *@param syncTaskVo
	 *@return
	 */
	@ApiOperation(value="获取单个异步任务", notes="获取单个异步任务")
	@ApiImplicitParam(dataType="SyncTaskVo", name="syncTaskVo", value="异步任务信息", required=true, paramType="body")
	@PostMapping("/getbyid")
	public Response getById(final HttpServletRequest request, @RequestBody SyncTaskVo syncTaskVo) {
		
		LOGGER.info("获得单个异步任务开始...");
		try {
			final Response validateResponse = validateBasicParams(syncTaskVo, true);
			if(validateResponse.getCode()!=Cons.RESPONSE_CODE_SUCCESS) {
				return validateResponse;
			}
			if(syncTaskVo.getId()==null) {
				return new Response(Cons.RESPONSE_CODE_PARAM_INVALID, "任务ID不能为空");
			}
			if(validateResponse.getCode()!=Cons.RESPONSE_CODE_SUCCESS) {
				return validateResponse;
			}
			final Response resultResponse = syncTaskService.findById(syncTaskVo.getId(), syncTaskVo.getEnterpriseCode());
			LOGGER.info("获取单个异步任务详情接口返回结果:{}", JSONObject.toJSONString(resultResponse));
			return resultResponse;
		} catch (ServiceException e) {
			LOGGER.error("获得单个异步任务接口失败", e);
			return new Response(ResponseEnum.EXCEPTION);
		}
	}

}
